
import {React,useEffect,useState} from "react"
import {Button,List,Avatar,Space,Tag} from "antd"
import { ajax } from "../../api";
import { MessageOutlined, LikeOutlined, StarOutlined } from '@ant-design/icons';
import { baseURL } from "../../api/ajax";
const colors = ["#f50","#0f0","#6ff","pink","orange"]
                  
export default function PriviewAdvise({history,location}){
    const  [data,setData] = useState([])

    useEffect(()=>{
       
        ajax.getadviseone({
            _id:new URLSearchParams(location.search).get("aid")
        })
        .then(res=>{
            if(res.code==200){
                setData([res.result])
            }
        })
    },[])
    const hotAdd = (item)=>{
        ajax.addhot({
            _id:item._id,
            hot:++item.hot
        })
        .then(res=>{
            if(res.code==200){
                ajax.getadviseone({
                    _id:new URLSearchParams(location.search).get("aid")
                })
                .then(res=>{
                    if(res.code==200){
                        setData([res.result])
                    }
                })
            }
        })
    }
    return (
        <div>
            <h2 style={{margin:"10px 0 "}}>查看意见详情 </h2>
            <Button type="primary" onClick={()=>history.go(-1)} > 返回 </Button>
            <List
                itemLayout="vertical"
                size="large"
                pagination={{
                onChange: page => {
                    console.log(page);
                },
                pageSize: 3,
                }}
                dataSource={data}
               
                renderItem={(item,i) => (
                <List.Item
                    key={i}
                    actions={[
                        <Space onClick={()=>hotAdd(item)}>
                            <LikeOutlined  />  
                            <span>{item.hot}</span>
                        </Space>,
                    ]}
                    extra={
                    <img
                        width={272}
                        alt="logo"
                        src="https://gw.alipayobjects.com/zos/rmsportal/mqaQswcyDLcXyDKnZfES.png"
                    />
                    }
                >
                    <List.Item.Meta
                    avatar={<Avatar src={item.avatar.replace(/public/,baseURL)} />}
                    title={<a  >{item.title} -- {item.author}</a>}
                    description={
                        item.category.map((l,i)=>{
                            return (<Tag key={i} color={colors[i]} > {l}</Tag>)
                        })
                    }
                    />
                    <div dangerouslySetInnerHTML={{__html:item.content}}>
                      
                    </div>
                </List.Item>
                )}
            />
        </div>
    )
}